

/**
 * DataTables
 */
var datatable = null,idList=[];

$(function() {
	getIssuePeriodSelectList();
	getScenicSpotSelectList();
	datatable = $('.table-sort').dataTable({
		order: [
			[1, 'asc']
		],
		bRetrieve: true,
		autoWidth: true,
		searching : false,
		lengthChange: false,	
		processing: true, //当datatable获取数据时候是否显示正在处理提示信息。
		serverSide: true, //服务器处理分页
		responsive: {
			details: false
		},
	    //lengthMenu: [100],   // 每页显示数据（默认是10）
	    ordering: false,//是否允许用户排序
	    paging: true,//是否分页
	    pagingType: "full_numbers",//除首页、上一页、下一页、末页四个按钮还有页数按钮
	    /* scrollX: true,//允许水平滚动
	     scrollY: "200px",
	     scrollCollapse: true, */
	    stateSave: false,//刷新时是否保存状态
	    //deferRender: true,//延迟渲染
		ajax: {
			url: contextPath + "/issuePeriodScenicSpot/getPageList",
			type: 'post',
			data: function(d) {
				d.issuePeriodId = $('#issuePeriodSelectList').val();
			}
		},	
		language: {
			"url": "../resources/js/datatables_language.json"
		},
		columns: [
			{data: "periodSpotId"},
			{data: "issueSETime",defaultContent: ""},
			{data: "scenicSpot",defaultContent: ""},
			{data: "splitPattern",defaultContent: ""},
			{data: "split",defaultContent: ""},
			{data: "limitTimes",defaultContent: ""},
			{data: "discount",defaultContent: ""},
			{data: "createTime",defaultContent: ""},
			{data: null}
			],
		columnDefs: [{
			targets: [0],
			orderable:false,
			render: function(data, type, row, meta) {
				return '<input id="input-' + data + '" type="checkbox" name="single"><label for="input-' + data + '"></label>';
			}  
		}, {
			targets: [3],
			render: function(data, type, row, meta) {
				if (data == 1) return '比例分成';
				else if (data == 2) return '权重';
				else if (data == 3) return '免费';
			}
		}, {
			targets: [7],
			render: function(data, type, row, meta) {
				return data ? new Date(data).pattern("yyyy-MM-dd HH:mm:ss") : '';
			}
		},  {
			targets: [8],
			orderable:false,
			responsivePriority: 1,
			render: function(data, type, row, meta) {
				var btns = new Array('del');
				return getDTOperateBtn(btns, row.periodSpotId, null, null, '/issuePeriodScenicSpot/delete', reloadTable);
			}
		}]
	});

});


function getIssuePeriodSelectList(){
	jQuery.ajax({
	      type:"POST",
	      dataType:"json",
	      url:contextPath + "/issuePeriod/getSelectList",
	      success:function(data){
	        var unitObj=document.getElementById("issuePeriodSelectList");
	        if(data != null){ 
	        	//alert(JSON.stringify(selectList));
	          for(var i = 0; i < data.length; i++){
	          //先创建好select里面的option元素
	            var option = document.createElement("option");
	            //转换DOM对象为JQ对象,好用JQ里面提供的方法 给option的value赋值
	            $(option).val(data[i].value);
	            //给option的text赋值,这就是你点开下拉框能够看到的东西
	            $(option).text(data[i].text);
	            //获取select 下拉框对象,并将option添加进select
	            $('#issuePeriodSelectList').append(option);
	            if (i == 0)
	            	option.selected = true;
	          }
	        }
	      },
	      error:function(){
	        J.alert('Error loading Json document');        
	      }
	    });
}

function getScenicSpotSelectList(){
	jQuery.ajax({
	      type:"POST",
	      dataType:"json",
	      url:contextPath + "/scenicSpot/getSelectList",
	      success:function(data){
	        var unitObj=document.getElementById("scenicSpotSelectList");
	        if(data != null){ 
	        	//alert(JSON.stringify(selectList));
	          for(var i = 0; i < data.length; i++){
	          //先创建好select里面的option元素
	            var option = document.createElement("option");
	            //转换DOM对象为JQ对象,好用JQ里面提供的方法 给option的value赋值
	            $(option).val(data[i].value);
	            //给option的text赋值,这就是你点开下拉框能够看到的东西
	            $(option).text(data[i].text);
	            //获取select 下拉框对象,并将option添加进select
	            $('#scenicSpotSelectList').append(option);
	            if (i == 0)
	            	option.selected = true;
	          }
	        }
	      },
	      error:function(){
	        J.alert('Error loading Json document');        
	      }
	    });
}

function selectOnchange(){
	$('.table-sort').dataTable().fnDraw(false);
}
